<!--
 * @Author: ningjz
 * @Date: 2022-03-25 11:30:00
 * @Description: 基本情况-弹窗数据
-->

<template>
  <div class="box">
    <div class="box-close" @click="handClose">
      <el-icon><close /></el-icon>
    </div>
    <div class="box-con">
      <div class="form-item">
        <div class="form-label">标题：</div>
        <el-input
          v-model="title"
          style="width: 526px"
          maxlength="10"
          placeholder="请输入标题"
        />
      </div>
      <div class="form-item">
        <div class="form-label">详细内容：</div>
        <el-input
          v-model="content"
          :rows="4"
          type="textarea"
          style="width: 526px"
          placeholder="请输入详细内容"
        />
      </div>
      <div class="con-btn">
        <button @click="handBoxClick('confirm')" v-if="msgType == 'add'">
          确认
        </button>
        <button @click="handBoxClick('close')">关闭</button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, watch } from 'vue'
import { Close } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { CircleCheck, CircleClose } from '@element-plus/icons-vue'
import request from '@/utils/request'
interface IState {
  title: string
  content: string
  data: any[]
}
export default defineComponent({
  components: {
    Close
  },
  props: {
    msg: {
      type: Object,
      default: () => ({})
    },
    msgType: {
      type: String,
      default: () => {
        return ''
      }
    },
    msgList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  setup(props, { emit }) {
    const state: IState = reactive({
      title: '',
      content: '',
      data: []
    })
    const handClose = () => {
      state.title = ''
      state.content = ''
      emit('close')
    }
    const handBoxClick = (val: string) => {
      if (val == 'confirm') {
        if (state.title == '') {
          ElMessage({
            message: '标题不能为空',
            showClose: true,
            offset: 130,
            duration: 2000,
            type: 'warning'
          })
          return
        }
        let id = props.msgList[props.msg.componentIndex]
        const params = {
          dateTime: props.msg.name,
          waveReason: state.content,
          waveTitle: state.title,
          zsCpiId: id,
          type: 'huan_bizhishu',
          id: ''
        }
        request(
          '/dataservice/priceIndex/insertWaveReason',
          JSON.stringify(params),
          'post',
          'json'
        ).then((res: any) => {
          if (res.code == 200) {
            ElMessage({
              message: '操作成功！',
              showClose: true,
              offset: 130,
              duration: 2000,
              type: 'success'
            })
            handClose()
            emit('refresh')
          }
        })
      } else {
        handClose()
      }
    }
    watch(
      () => props.msg,
      (newVal) => {
        if (props.msgType == 'query') {
          props.msgList.forEach((i: any) => {
            if (i.reason_id == props.msg.name) {
              state.title = i.title
              state.content = i.reason
            }
          })
        } else if (props.msgType == 'add') {
          console.log(props.msgList)
          console.log(props.msg)
        }
      }
    )
    const { title, data, content } = toRefs(state)
    return {
      handClose,
      handBoxClick,
      data,
      title,
      content
    }
  }
})
</script>

<style lang="less" scoped>
.box {
  height: 100%;
  width: 100%;
  padding: 90px 40px 40px 40px;
  background: url('../../../assets/images/table-bg.png') no-repeat;
  background-size: 100% 100%;
  position: relative;
  .box-close {
    cursor: pointer;
    position: absolute;
    right: 12px;
    top: 16px;
    font-size: 38px;
    color: #ccfdff;
    &:hover {
      color: #8ca8a8;
    }
  }
  .form-item {
    display: flex;
    align-items: center;
    margin-bottom: 40px;
    .form-label {
      font-size: 32px;
      font-weight: bold;
      width: 165px;
      text-align: right;
    }
    ::v-deep(.el-input__inner) {
      border-radius: 8px;
      color: rgb(255, 255, 255);
      box-shadow: none !important;
      height: 48px;
      font-size: 24px;
      line-height: 48px;
    }
    ::v-deep(.el-textarea__inner) {
      border-radius: 8px;
      color: rgb(255, 255, 255);
      box-shadow: none !important;
      font-size: 24px;
      line-height: 32px;
      padding: 16px;
      min-height: 120px;
    }
  }
  .box-con {
    // background: url('../../../assets/images/M2/table-gb.png') no-repeat;
    background-size: 100% 100%;
    width: 100%;
    height: 100%;
    .con-item {
      display: flex;
      height: 56.8px;
      margin-bottom: 3px;
      font-weight: 550;
      // color: #88e0ff;
      color: #1deeff;
      font-size: 18px;
      .item-con {
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #153f7e;
      }
      &:nth-child(1) {
        color: #fff;
        .item-con {
          background-color: #0387cf;
        }
        .con-nav {
          background-color: #0387cf;
          justify-content: center;
        }
      }
      .con-til {
        width: 231px;
        // background: #ff712b;
      }
      .con-nav {
        margin-left: 3px;
        width: 825px;
        padding: 0px 25px;
        justify-content: flex-start;
        // background: #b45af3;
      }
    }
  }
  .con-btn {
    display: flex;
    justify-content: center;
    margin-top: 42px;
    button {
      cursor: pointer;
      background: #14519c;
      padding: 12px 30px;
      color: #fff;
      font-weight: bold;
      box-shadow: 0 0 14px #297eea inset;
      border: 1px solid transparent;
      margin: 0px 20px;
      display: flex;
      align-items: center;
      font-size: 36px;
      i {
        font-size: 38px;
        margin-right: 10px;
      }
    }
  }
}
</style>
